﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace IceDog.MDIBasic.SubForm
{
    public partial class FormProgressBar : Form
    {
        private Timer timer = null;
        public FormProgressBar(FormMain parent,int counter)
        {
            InitializeComponent();
            this.Text = "Process " + counter.ToString();
            var ran = new Random();
            timer = new Timer();
            timer.Interval = 200;
            timer.Tick += (s, e) =>
            {
                if (this.progressBarBlock.Value < this.progressBarBlock.Maximum)
                {
                    var val = this.progressBarBlock.Value + ran.Next(1, 5);
                    if (val > 95)
                    {
                        this.progressBarBlock.Value = 100;
                    }
                    else
                    {
                        this.progressBarBlock.Value += ran.Next(1, 5);
                    }

                }
                if (this.progressBarContinuous.Value < this.progressBarContinuous.Maximum)
                {
                    var val = this.progressBarContinuous.Value + ran.Next(1, 5);
                    if (val > 95)
                    {
                        this.progressBarContinuous.Value = 100;
                    }
                    else
                    {
                        this.progressBarContinuous.Value += ran.Next(1, 5);
                    }
                }
                if (this.progressBarMarquee.Value < this.progressBarMarquee.Maximum)
                {
                    var val = this.progressBarMarquee.Value + ran.Next(1, 5);
                    if (val > 95)
                    {
                        this.progressBarMarquee.Value = 100;
                    }
                    else
                    {
                        this.progressBarMarquee.Value += ran.Next(1, 5);
                    }
                }
            };
            this.MdiParent = parent;
        }

        private void buttonStart_Click(object sender, EventArgs e)
        {
            this.timer.Start();
        }

        private void buttonStop_Click(object sender, EventArgs e)
        {
            this.timer.Stop();
        }

        private void ToolStripMenuItemStart_Click(object sender, EventArgs e)
        {
            this.timer.Start();
        }

        private void ToolStripMenuItemStop_Click(object sender, EventArgs e)
        {
            this.timer.Stop();
        }
    }
}
